/*
 * Util.java
 *
 * Created on 5 de julio de 2007, 17:05
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package daw.util;

import com.griaule.grfingerjava.FingerprintImage;
import com.griaule.grfingerjava.GrFingerJava;
import com.griaule.grfingerjava.MatchingContext;
import com.griaule.grfingerjava.Template;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageReader;
import javax.imageio.spi.IIORegistry;
import javax.imageio.spi.ImageReaderSpi;

/**
 *
 * @author SkateTuco
 */
public class Util {
    
    /** Creates a new instance of Util */
    public Util() {
    }
 
    public static byte[] getStringToTemplate(String plantilla){
        String[] bs = plantilla.split(",");
        int tam = bs.length;
        byte[] b = new byte[tam];
        for(int j=0;j<tam;j++){
            b[j] = Byte.parseByte(bs[j].trim());
        }
        return b;
    }
    
     public static byte[] getStringToHuella(String huella){
        String[] bs = huella.split(",");
        int tam = bs.length;
        byte[] b = new byte[tam];
        for(int j=0;j<tam;j++){
            b[j] = Byte.parseByte(bs[j].trim());
        }
        return b;
    } 
     
    public static byte[] getTemplate(byte[] huella, int ancho, int alto, int resolucion){
        try {            
            FingerprintImage fimg = new FingerprintImage(huella,ancho,alto,resolucion);
            GrFingerJava.setLicenseDirectory(new File("/SIAIWEB/Usuarios/USU/bin"));
            GrFingerJava.setNativeLibrariesDirectory(new File("/SIAIWEB/Usuarios/USU/bin"));
            Template t = new MatchingContext().extract(fimg);
            return t.getData();
        } catch (Exception ex) {
            System.out.println("No se puede extraer plantilla de huella digital.");
            System.out.println(ex.getMessage());
        }
        return null;
    }
    
}